package ovm.gui.buttons.table;

import ovm.gui.forms.AbstractEntityForm;
import ovm.gui.forms.EntityFormFactory;
import ovm.gui.views.EntityViewFactory;
import ovm.management.AbstractManager;

import static ovm.application.MainApplication.navigator;

/**
 * Created by IntelliJ IDEA.
 * User: Jokser
 * Date: 28.05.12
 * Time: 8:55
 * To change this template use File | Settings | File Templates.
 */

public class EntityViewButton extends AbstractTableButton {

    Class entityClass;
    Object entity;
    Boolean editable;

    public EntityViewButton(String caption, Class entityClass, Integer entityId, Boolean editable) {
        super(caption);
        this.entityClass = entityClass;
        this.entity = AbstractManager.getAbstractEntityById(entityClass, entityId);
        this.editable = editable;
    }

    @Override
    public void buttonClick(ClickEvent event) {
        AbstractEntityForm form = EntityFormFactory.createEntityForm(entityClass, entity, editable);
        navigator.setMainView(EntityViewFactory.createEntityView(entityClass, form, editable));
    }
}